import express from 'express';
import { createServer } from 'http';
import { Server } from 'socket.io';
// 在现有import后添加
import authRoutes from './routes/authRoutes';
import questionRoutes from './routes/questionRoutes';
import examReviewRoutes from './routes/exam-review';

const app = express();
const httpServer = createServer(app);
const io = new Server(httpServer, {
  cors: {
    origin: "*"
  }
});

// Middleware
app.use(express.json());

// Routes
app.get('/', (req, res) => {
  res.send('Online Test System API');
});

// Socket.IO connection
io.on('connection', (socket) => {
  console.log('A user connected');
  
  socket.on('disconnect', () => {
    console.log('User disconnected');
  });
});

const PORT = process.env.PORT || 3000;
httpServer.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
});

// 在现有中间件后添加
app.use('/api/auth', authRoutes);
app.use('/api/questions', questionRoutes);
app.use('/api/exam-review', examReviewRoutes);